/* eslint-disable @typescript-eslint/no-var-requires */
import typescript from 'rollup-plugin-typescript2';
import json from '@rollup/plugin-json';
import cpy from 'rollup-plugin-cpy';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import { preserveShebangs } from 'rollup-plugin-preserve-shebangs';
const extensions = ['.js', '.ts'];

export default {
  // 输入目录
  input: './server.ts',
  // 输出目录
  output: {
    dir: './lib',
    format: 'cjs'
  },
  plugins: [
    // 处理#!/usr/bin/env node
    preserveShebangs(),
    // 处理json依赖
    json(),
    // 解析typescript
    typescript({
      tsconfigOverride: {
        compilerOptions: {
          module: 'ESNext'
        }
      }
    }),
    // 解析代码中依赖的node_modules
    nodeResolve({
      extensions,
      modulesOnly: true,
      preferredBuiltins: false
    }),
    // 代码压缩
    terser(),
    // 拷贝静态资源
    cpy([
      { files: 'config/*.json', dest: './lib' },
      { files: 'public/*', dest: './lib/public' }
    ])
  ]
};
